﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using OgilvyOne.IDAL;
using OgilvyOne.Model;

namespace OgilvyOne.SqlServerDAL
{
    public class StockInfoSql : IStockInfo
    {
        /// <summary>
        /// 获取公司股票信息
        /// </summary>
        /// <param name="sid"></param>
        /// <returns></returns>
        public StockInfoModel GetModel(int sid)
        {
            StockInfoModel mim = null;
            string sql = "select id,company,price,per,circs,path from StockInfo where id=" + sid;
            SqlParameter[] parms = new SqlParameter[] { };

            using (SqlDataReader rdr = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_STOCK, CommandType.Text, sql, parms))
            {
                if (rdr.Read())
                {
                    mim = new StockInfoModel();
                    mim.ID = rdr.GetInt32(0);
                    if (!rdr.IsDBNull(1)) mim.Company = rdr.GetString(1);
                    if (!rdr.IsDBNull(2)) mim.Price = rdr.GetString(2);
                    if (!rdr.IsDBNull(3)) mim.Per = rdr.GetString(3);
                    if (!rdr.IsDBNull(4)) mim.Circs = rdr.GetString(4);
                    if (!rdr.IsDBNull(5)) mim.Path = rdr.GetString(5);
                    

                }
            }
            return mim;
        }
        /// <summary>
        /// 所有公司股票实时数据
        /// </summary>
        /// <returns></returns>
        public IList<StockInfoModel> GetList()
        {
            IList<StockInfoModel> datalist = new List<StockInfoModel>();
            string sql = "select id,company,price,per,circs,path from StockInfo where id<>6 and id<>8 order by id";
            SqlParameter[] parms = new SqlParameter[] { };

            using (SqlDataReader rdr = SQLHelper.ExecuteReader(SQLHelper.CONN_STRING_STOCK, CommandType.Text, sql, parms))
            {
                while (rdr.Read())
                {
                    StockInfoModel mim = new StockInfoModel();
                    mim.ID = rdr.GetInt32(0);
                    if (!rdr.IsDBNull(1)) mim.Company = rdr.GetString(1);
                    if (!rdr.IsDBNull(2)) mim.Price = rdr.GetString(2);
                    if (!rdr.IsDBNull(3)) mim.Per = rdr.GetString(3);
                    if (!rdr.IsDBNull(4)) mim.Circs = rdr.GetString(4);
                    if (!rdr.IsDBNull(5)) mim.Path = rdr.GetString(5);
                    datalist.Add(mim);

                }
            }
            return datalist;
        }
    }
}
